﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Globalization;


public partial class EnergyEntry_gas : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            UpdateGas();

        }
    }

    
    protected void btnSubmitGas_Click(object sender, EventArgs e)
    {
        DateTime dtReadingDate = DateTime.Parse(txtGasDate.Text, CultureInfo.CreateSpecificCulture("en-GB").DateTimeFormat);
        decimal GasReading = decimal.Parse(txtGasReading.Text);


       // var newReadings = UpdateHelper.CreateGasReadings(dtReadingDate, GasReading);

       // lblGasInfo.Text = string.Format("Add {0} records, from {1} to {2}, average value {3}cubM?", newReadings.Count, newReadings.First().dg_dateTime.ToLongDateString(), newReadings.Last().dg_dateTime.ToLongDateString(), newReadings.First().dg_cubicMDaily);
        btnConfirmGas.Visible = true;
        btnCancelGas.Visible = true;
        btnSubmitGas.Visible = false;
    }
    protected void btnConfirmGas_Click(object sender, EventArgs e)
    {
        DateTime dtReadingDate = DateTime.Parse(txtGasDate.Text, CultureInfo.CreateSpecificCulture("en-GB").DateTimeFormat);
        decimal GasReading = decimal.Parse(txtGasReading.Text);


        //var newReadings = UpdateHelper.CreateGasReadings(dtReadingDate, GasReading);
        //UpdateHelper.SaveNewGasReadings(newReadings);

       // lblGasInfo.Text = string.Format("Added {0} records, from {1} to {2}, average value {3}cubM", newReadings.Count, newReadings.First().dg_dateTime.ToLongDateString(), newReadings.Last().dg_dateTime.ToLongDateString(), newReadings.First().dg_cubicMDaily);


        UpdateGas();
        btnConfirmGas.Visible = false;
        btnCancelGas.Visible = false;
        btnSubmitGas.Visible = true;
    }
    protected void btnCancelGas_Click(object sender, EventArgs e)
    {
        btnConfirmGas.Visible = false;
        btnCancelGas.Visible = false;
        btnSubmitGas.Visible = true;
    }

    private void UpdateGas()
    {
        //WeatherDbDataContext db = new WeatherDbDataContext();
        //var Gas = db.DailyGas.OrderByDescending(dg => dg.dg_dateTime);
        ////dgGas.DataSource = Gas;

        //var firstGas = Gas.FirstOrDefault();
        //DateTime dtmGas;
        //decimal GasReading;
        //if (firstGas != null)
        //{
        //    dtmGas = firstGas.dg_dateTime.AddDays(1);
        //    GasReading = firstGas.dg_cubicMTotal.Value;

        //}
        //else
        //{
        //    dtmGas = DateTime.Now.Date;
        //    GasReading = 0;
        //}
        //txtGasDate.Text = dtmGas.ToString(CultureInfo.CreateSpecificCulture("en-GB").DateTimeFormat.ShortDatePattern);
        //txtGasReading.Text = ((int)GasReading).ToString();
    }

}
